package com.example.test;

import java.util.Date;

public class LockFast {
    private static final Object lock=new Object();
    private static volatile int count=1;
    private static volatile int max=100;

    public static void main(String[] args) {
//        Thread thread1=new Thread(new Seq(1));
//        Thread thread0=new Thread(new Seq(0));
//        thread1.start();
//        thread0.start();
        int result = new Date().compareTo(new Date(System.currentTimeMillis()+10000));
        System.out.println(result);
    }
    static class Seq implements Runnable{
        private final int index;

        Seq(int index) {
            this.index = index;
        }

        @Override
        public void run() {
            while(index<max){
                synchronized (lock){
                    try {
                        while (count % 2 != index) {
                            lock.wait();
                        }
                        if (count <= max) {
                            System.out.println(("thread-" + index + ":" + count));
                        }
                        count++;
                        lock.notifyAll();
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }

        }
    }
}
